package com.chat.datea.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentManager;

import com.chat.datea.fragment.SearchResultMidiFragment;
import com.chat.datea.fragment.SearchResultSingerFragment;
import com.chat.datea.fragment.SongAlbumFragment;
import com.chat.datea.fragment.SongFragment;

import java.util.ArrayList;

/**
 * Created by Shura on 15/11/3.
 */
public class SearchResultAdapter extends FragmentPagerAdapter {
    private FragmentManager fragmentManager;
    private ArrayList<Fragment> fragments;
    private String[] title = {"歌曲", "专辑", "歌手", "伴奏"};

    public SearchResultAdapter(FragmentManager fragmentManager, FragmentManager childFragmentManager) {
        super(childFragmentManager);
        this.fragmentManager = fragmentManager;
        initData();
    }

    private void initData() {
        fragments = new ArrayList<>();
        fragments.add(new SongFragment());
        fragments.add(new SongAlbumFragment());
        fragments.add(new SearchResultSingerFragment());
        fragments.add(new SearchResultMidiFragment());
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.size() > 0 && fragments != null ? fragments.get(position) : null;
    }

    @Override
    public int getCount() {
        return fragments.size() > 0 && fragments != null ? fragments.size() : 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return title[position];
    }
}
